{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy import stats\n",
    "import pymysql\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "plt.rcParams['font.family']='SimHei'\n",
    "plt.rcParams['axes.unicode_minus']= False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>group</th>\n",
       "      <th>landing_page</th>\n",
       "      <th>converted</th>\n",
       "      <th>data</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>851104</td>\n",
       "      <td>2017-01-21 22:11:48.556739</td>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>0</td>\n",
       "      <td>2017-01-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>804228</td>\n",
       "      <td>2017-01-12 08:01:45.159739</td>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>0</td>\n",
       "      <td>2017-01-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>661590</td>\n",
       "      <td>2017-01-11 16:55:06.154213</td>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>0</td>\n",
       "      <td>2017-01-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>853541</td>\n",
       "      <td>2017-01-08 18:28:03.143765</td>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>0</td>\n",
       "      <td>2017-01-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>864975</td>\n",
       "      <td>2017-01-21 01:52:26.210827</td>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>1</td>\n",
       "      <td>2017-01-21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id                   timestamp      group landing_page  converted  \\\n",
       "0   851104  2017-01-21 22:11:48.556739    control     old_page          0   \n",
       "1   804228  2017-01-12 08:01:45.159739    control     old_page          0   \n",
       "2   661590  2017-01-11 16:55:06.154213  treatment     new_page          0   \n",
       "3   853541  2017-01-08 18:28:03.143765  treatment     new_page          0   \n",
       "4   864975  2017-01-21 01:52:26.210827    control     old_page          1   \n",
       "\n",
       "         data  \n",
       "0  2017-01-21  \n",
       "1  2017-01-12  \n",
       "2  2017-01-11  \n",
       "3  2017-01-08  \n",
       "4  2017-01-21  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('ab_data.csv')\n",
    "data[\"data\"] = data.timestamp.str[:10]\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 检验指标确定"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一类指标：人均停留时间长，保证一类指标不下降的或者在正常的波动范围内\n",
    "二类指标：广告点击率"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 确定检验统计量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一类指标：人均停留时长，用人均停留时长之差作为统计量\n",
    "二类指标：广告点击率 = 点击用户数/曝光用户数，用两组广告点击率之差作为统计量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 埋点收集数据"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 确定H0，H1\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 确定显著水平α"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "alpha = 0.05\n",
    "beta = 0.2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "code_folding": []
   },
   "source": [
    "# 计算样本量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.1203863045004612"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "control_p = data.converted[(data.group == \"control\")&(data.landing_page == \"old_page\")].mean()\n",
    "control_p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.10589344218918344"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "control_p_1_control_p = control_p*(1-control_p)\n",
    "control_p_1_control_p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.6448536269514729"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Z1_alpha = stats.norm.isf(alpha,loc=0,scale=1)\n",
    "Z1_alpha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.84162123357291418"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Z1_beta = stats.norm.isf(beta,loc=0,scale=1)\n",
    "Z1_beta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.13538630450046119 0.014999999999999986\n"
     ]
    }
   ],
   "source": [
    "treatment_p = control_p +0.015\n",
    "p_p0 = treatment_p - control_p\n",
    "print(treatment_p,p_p0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.11705685305416959"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_1_p = treatment_p*(1-treatment_p)\n",
    "p_1_p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6126.2353788343908"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = (control_p_1_control_p + p_1_p)*((Z1_alpha+Z1_beta)/p_p0)**2\n",
    "n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>group</th>\n",
       "      <th>landing_page</th>\n",
       "      <th>data</th>\n",
       "      <th>user_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-02</td>\n",
       "      <td>2859</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-03</td>\n",
       "      <td>6590</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-04</td>\n",
       "      <td>6578</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>6427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-06</td>\n",
       "      <td>6606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-07</td>\n",
       "      <td>6604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-08</td>\n",
       "      <td>6687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-09</td>\n",
       "      <td>6628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-10</td>\n",
       "      <td>6654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-11</td>\n",
       "      <td>6688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-12</td>\n",
       "      <td>6522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-13</td>\n",
       "      <td>6552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-14</td>\n",
       "      <td>6548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-15</td>\n",
       "      <td>6714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-16</td>\n",
       "      <td>6591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-17</td>\n",
       "      <td>6617</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-18</td>\n",
       "      <td>6482</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-19</td>\n",
       "      <td>6578</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-20</td>\n",
       "      <td>6534</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-21</td>\n",
       "      <td>6749</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-22</td>\n",
       "      <td>6596</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-23</td>\n",
       "      <td>6716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>2017-01-24</td>\n",
       "      <td>3754</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-02</td>\n",
       "      <td>2853</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-03</td>\n",
       "      <td>6618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-04</td>\n",
       "      <td>6541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>6505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-06</td>\n",
       "      <td>6747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-07</td>\n",
       "      <td>6609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-08</td>\n",
       "      <td>6700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-09</td>\n",
       "      <td>6615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-10</td>\n",
       "      <td>6696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-11</td>\n",
       "      <td>6673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-12</td>\n",
       "      <td>6637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-13</td>\n",
       "      <td>6508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-14</td>\n",
       "      <td>6600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-15</td>\n",
       "      <td>6549</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-16</td>\n",
       "      <td>6545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-17</td>\n",
       "      <td>6538</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-18</td>\n",
       "      <td>6603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-19</td>\n",
       "      <td>6552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-20</td>\n",
       "      <td>6679</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-21</td>\n",
       "      <td>6560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-22</td>\n",
       "      <td>6669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-23</td>\n",
       "      <td>6633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>2017-01-24</td>\n",
       "      <td>3681</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        group landing_page        data  user_id\n",
       "23    control     old_page  2017-01-02     2859\n",
       "24    control     old_page  2017-01-03     6590\n",
       "25    control     old_page  2017-01-04     6578\n",
       "26    control     old_page  2017-01-05     6427\n",
       "27    control     old_page  2017-01-06     6606\n",
       "28    control     old_page  2017-01-07     6604\n",
       "29    control     old_page  2017-01-08     6687\n",
       "30    control     old_page  2017-01-09     6628\n",
       "31    control     old_page  2017-01-10     6654\n",
       "32    control     old_page  2017-01-11     6688\n",
       "33    control     old_page  2017-01-12     6522\n",
       "34    control     old_page  2017-01-13     6552\n",
       "35    control     old_page  2017-01-14     6548\n",
       "36    control     old_page  2017-01-15     6714\n",
       "37    control     old_page  2017-01-16     6591\n",
       "38    control     old_page  2017-01-17     6617\n",
       "39    control     old_page  2017-01-18     6482\n",
       "40    control     old_page  2017-01-19     6578\n",
       "41    control     old_page  2017-01-20     6534\n",
       "42    control     old_page  2017-01-21     6749\n",
       "43    control     old_page  2017-01-22     6596\n",
       "44    control     old_page  2017-01-23     6716\n",
       "45    control     old_page  2017-01-24     3754\n",
       "46  treatment     new_page  2017-01-02     2853\n",
       "47  treatment     new_page  2017-01-03     6618\n",
       "48  treatment     new_page  2017-01-04     6541\n",
       "49  treatment     new_page  2017-01-05     6505\n",
       "50  treatment     new_page  2017-01-06     6747\n",
       "51  treatment     new_page  2017-01-07     6609\n",
       "52  treatment     new_page  2017-01-08     6700\n",
       "53  treatment     new_page  2017-01-09     6615\n",
       "54  treatment     new_page  2017-01-10     6696\n",
       "55  treatment     new_page  2017-01-11     6673\n",
       "56  treatment     new_page  2017-01-12     6637\n",
       "57  treatment     new_page  2017-01-13     6508\n",
       "58  treatment     new_page  2017-01-14     6600\n",
       "59  treatment     new_page  2017-01-15     6549\n",
       "60  treatment     new_page  2017-01-16     6545\n",
       "61  treatment     new_page  2017-01-17     6538\n",
       "62  treatment     new_page  2017-01-18     6603\n",
       "63  treatment     new_page  2017-01-19     6552\n",
       "64  treatment     new_page  2017-01-20     6679\n",
       "65  treatment     new_page  2017-01-21     6560\n",
       "66  treatment     new_page  2017-01-22     6669\n",
       "67  treatment     new_page  2017-01-23     6633\n",
       "68  treatment     new_page  2017-01-24     3681"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd = data.groupby([\"group\",\"landing_page\",\"data\"],as_index=False)[\"user_id\"].count()\n",
    "dd[((dd.group==\"control\")&(dd.landing_page==\"old_page\"))|((dd.group==\"treatment\")&(dd.landing_page==\"new_page\"))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>group</th>\n",
       "      <th>landing_page</th>\n",
       "      <th>converted</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>control</td>\n",
       "      <td>new_page</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>control</td>\n",
       "      <td>old_page</td>\n",
       "      <td>6590</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>treatment</td>\n",
       "      <td>new_page</td>\n",
       "      <td>6618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>treatment</td>\n",
       "      <td>old_page</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       group landing_page  converted\n",
       "0    control     new_page         94\n",
       "1    control     old_page       6590\n",
       "2  treatment     new_page       6618\n",
       "3  treatment     old_page         92"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = data[data.data==\"2017-01-03\"].groupby([\"group\",\"landing_page\"],as_index=False)[\"converted\"].count()\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "statistic_t = df.converted[2]-df.converted[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "n1=data[data.data==\"2017-01-03\"].converted[(data.group==\"control\")&(data.landing_page)]\n",
    "n2=data[data.data==\"2017-01-03\"].converted[(data.group==\"treatment\")&(data.landing_page)]\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
